<?php

/**
 * usuario_garantia actions.
 *
 * @package    sispatr
 * @subpackage usuario_garantia
 * @author     Foxsis
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class usuario_garantiaActions extends sfActionsFoxsis
{
  public function executeIndex(sfWebRequest $request)
  {
    return $this->forward('usuario_garantia', 'list');
  }


	public function executeSave(sfWebRequest $request)
	{
		$this->forward404Unless($request->isMethod(sfRequest::POST));

		$this->form = new UsuarioGarantiaForm($this->getUser()->getFormObject()->DadosUsuarioGarantia);

		$this->processForm($request, $this->form);

		$this->forward('formulario', 'garantias');

	}

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
  	try
		{

			$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));

			if ($form->isValid())
			{
				$form->getObject()->setIdDadosUsuario($this->getUser()->getIdDadosUsuario());				
				$dados_usuario_referencias = $form->save();
				
				$this->getUser()->setFlash('mensagem', 'Dados salvos com sucesso');
				$this->redirect('formulario/garantias');
			}
			else
			{
				throw new Exception($this->form->getErrorSchema());
			}
		}
		catch(Exception $e)
		{
			$this->getUser()->setFlash('erro', $e->getMessage());
		}
  }
}
